package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.MainBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.net.URL;

/**
 * Created by lihao on 2017/9/12.
 */

public class MainPresenter extends basePresenter {

    private Contract.MainView mainView;

    public MainPresenter(Contract.MainView view) {
        super(view);
        this.mainView = view;
    }

    public void initData(String latitude,String longitude) {
        RequestParams rp = new RequestParams(URLS.HOST+ URLS.INDEX_DATA);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("latitude", latitude);
        rp.addBodyParameter("longitude", longitude);
        x.http().post(rp, new myCallback(BaseActivity.context, MainBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                MainBean bean = (MainBean) baseBean;
                mainView.setData(bean);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                mainView.onFail();
            }
        });
    }
}
